﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Text;

using Common;
using DAL;

namespace Core
{
    public class SimpleTableInfoList
    {
        private List<SimpleTableInfo> m_List = new List<SimpleTableInfo>();
        public SimpleTableInfoList(string providerName, string connectionString)
        {
            SchemaHeler schemaHeler = new SchemaHeler(providerName, connectionString);
            DataTable tableSchemas = schemaHeler.GetTables();
            for (int i = 0; i < tableSchemas.Rows.Count; i++)
            {
                DataRow dr = tableSchemas.Rows[i];
                var simpleTableInfo = new SimpleTableInfo();
                simpleTableInfo.Catalog = dr[TablePropName.TABLE_CATALOG].ToString();
                simpleTableInfo.Table_Schema = dr[TablePropName.TABLE_SCHEMA].ToString();
                simpleTableInfo.Name = dr[TablePropName.TABLE_NAME].ToString();
                simpleTableInfo.Table_Type = dr[TablePropName.TABLE_TYPE].ToString() == TablePropName.TABLE_TYPE__BASE_TABLE ? "T" : "V";
                //simpleTableInfo.Table_Type = dr[TablePropName.TABLE_TYPE].ToString();
                this.m_List.Add(simpleTableInfo);
            }
            this.m_List.Sort((x, y) => string.Compare(
                                                     x.Name,
                                                     y.Name));
            this.m_List.Sort((x, y) => string.Compare(
                                                     x.Table_Schema,
                                                     y.Table_Schema));
            this.m_List.Sort((x, y) => string.Compare(
                                                     x.Table_Type,
                                                     y.Table_Type));
        }
        public SimpleTableInfo this[int i]
        {
            get { return this.m_List[i]; }
        }

        public int Count
        {
            get { return this.m_List.Count; }
        }
    }
}
